package com.shioirikukuri.web.controller;

import com.shioirikukuri.common.web.Result;
import com.shioirikukuri.domain.SeckillProduct;
import com.shioirikukuri.service.ISeckillProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by shioirikukuri
 * 秒杀商品信息查询
 */
@RestController
@RequestMapping("/seckillProduct")
@Slf4j
public class SeckillProductController {
    @Autowired
    private ISeckillProductService seckillProductService;

    /**
     * 200 * 10
     * 根据时间段查询
     *    使用Redis前QPS:524/sec  约550
     *    使用Redis后QPS:1484/sec 约1400
     * @param time
     * @return
     */
    @RequestMapping("/queryByTime")
    public Result<List<SeckillProduct>> queryByTime(Integer time){
        List<SeckillProduct> list = seckillProductService.queryByTime(time);
        return Result.success(list);
    }

    @RequestMapping("/find")
    public Result<SeckillProduct> find(Long seckillId){
        SeckillProduct seckillProduct = seckillProductService.find(seckillId);
        return Result.success(seckillProduct);
    }
}
